# 带有点的文件名，主要用于图片，不在标准定义当中
import binascii

import mmh3 as mmh3


def normFileName_image(fileName):
    if not "." in fileName:
        return fileName.upper()
    tmps = fileName.split(".")
    fileSufx = tmps[-1].lower()
    tmps.remove(tmps[-1])
    filePrfx = ".".join(tmps).upper()

    return "{0}.{1}".format(filePrfx, fileSufx)


## 使用murmurhash3算法将新全文文件名进行HASH并按照规则组装成HASH目录
def generateHashName(fileName):
    hashCode = binascii.b2a_hex(mmh3.hash_bytes(fileName)).upper()[0:3]
    firstCode = chr(hashCode[0])
    secondCode = chr(hashCode[1])
    thirdCode = chr(hashCode[2])
    if thirdCode.isdigit():
        return firstCode + secondCode + str(int(thirdCode) % 5)
    elif thirdCode == 'D':
        return firstCode + secondCode + 'A'
    elif thirdCode == 'E':
        return firstCode + secondCode + 'B'
    elif thirdCode == 'F':
        return firstCode + secondCode + 'C'
    else:
        return firstCode + secondCode + thirdCode
